package com.ccx.coachsite.ui.own;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.ccx.coachsite.R;
import com.ccx.coachsite.bus.SoftInfo;
import com.ccx.coachsite.bus.UserInfo;
import com.ccx.coachsite.util.CommonViewUtils;
import com.ccx.coachsite.util.StringUtil;
import com.ccx.coachsite.webimage.ImageLoader;

public class OwerFriendDetailView extends OwerBaseView {
	private GridView mFriendGrid;
	private OwerFriendDetailItemAdapter mAdapter;
	private List<SoftInfo> mApp;
	private UserInfo mUserInfo;
	
	public OwerFriendDetailView(Context context, OwerMainBase superView, UserInfo userInfo) {
		super(context, superView);
		mUserInfo = userInfo;
		
		if(StringUtil.isEmpty(mUserInfo.getRole()))
		{
			loadData();
		}
		else
		{
			doRefreshDataSuccess();
		}
	}
	
	protected boolean onLoadData() 
	{
		return OwerProvider.getInstance().getFriendDetail(mContext, mUserInfo);	
	}
	
	protected void doRefreshDataSuccess()
	{
		TextView lblName = (TextView) findViewById(R.id.ower_friend_lblName);
		TextView lblphone = (TextView) findViewById(R.id.ower_friend_lblPhone);
		TextView lblRole = (TextView) findViewById(R.id.ower_friend_lblRole);
		ImageView imgStar = (ImageView) findViewById(R.id.ower_friend_imgRank);
		TextView lblFavCount = (TextView) findViewById(R.id.lbl_friend_favour_count);
		TextView lblFriendCount = (TextView) findViewById(R.id.lbl_friend_friend_count);
		
		lblName.setText(mUserInfo.getUsername());
		lblphone.setText(mUserInfo.getMobile());
		lblRole.setText(mUserInfo.getRole());
		lblFavCount.setText(mUserInfo.getCollectCount()+"");
		lblFriendCount.setText(mUserInfo.getFriendCount()+"/200");
		
		CommonViewUtils.SetStarImage(mUserInfo.getStar(), imgStar);		
		ImageView imgV =  (ImageView) findViewById(R.id.ower_friend_person_icon);
		imgV.setImageResource(R.drawable.ower_image_none);
		ImageLoader.loadBitmap(mUserInfo.getIcon(), imgV);
		
		mApp = mUserInfo.getSofts();
		if(mApp == null)
		{
			mApp = new ArrayList<SoftInfo>();
		}
		
		View noneView = findViewById(R.id.ower_friend_none_shared);
		mFriendGrid = (GridView) findViewById(R.id.ower_friend_detail_grid);
		if(mApp.size() == 0)
		{
			noneView.setVisibility(View.VISIBLE);
			mFriendGrid.setVisibility(View.GONE);
		}
		else
		{
			noneView.setVisibility(View.GONE);
			mFriendGrid.setVisibility(View.VISIBLE);
			mFriendGrid.setOnItemClickListener(new OnItemClickListener());
			mAdapter = new OwerFriendDetailItemAdapter(mContext, mApp);
			mFriendGrid.setAdapter(mAdapter);
		}
	}
	
	private class OnItemClickListener implements
			android.widget.AdapterView.OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> adapter, View v, int pos,
				long arg3) {

		}
	}
}
